# coding:utf-8
'''
Created on 2015年8月30日

@author: xjb
'''

def set_bit(bits, pos, state):
    '''
    pos从0开始
    '''
    idx = pos/8;
    mask = 0x80 >> (pos % 8)
    if state:
        bits[idx] = bits[idx] | mask
    else:
        bits[idx] = bits[idx] & (~mask)
        
    
def get_bit(bits, pos):
    idx = pos/8;
    mask = 0x80 >> (pos % 8)
    return 1 if (bits[idx] & mask) == mask else 0
